package com.rainsoft.center.isec.stream.library.service;

import com.rainsoft.center.isec.stream.library.entity.hbase.impl.RealidLoginout;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.io.Serializable;

/**
 * @Name com.rainsoft.center.isec.stream.library.service.LibService
 * @Description
 * @Author Elwyn
 * @Version 2017/11/29
 * @Copyright 上海云辰信息科技有限公司
 **/
public class LibService implements Serializable{
	private	Stat stat;
	private	UDB udb;

	public void statLib (SparkSession sparkSession, Dataset<Row> baseInfoTable,JavaRDD<RealidLoginout> realidLoginoutJavaRDD) {

		//根据接收到的数据生成Dataset
		Dataset<Row> machineCodeSet = sparkSession.createDataFrame(realidLoginoutJavaRDD, RealidLoginout.class)
				.selectExpr("machineCode", "loginTime", "idtype");
		//join缓存的基础信息和接收到的数据
		Dataset<Row> join = machineCodeSet.join(baseInfoTable, "machineCode").cache();
		String joinTable="joinTable";
		join.createOrReplaceTempView(joinTable);
		stat=new Stat();
		stat.saveRealCountByMachine(sparkSession, joinTable);
		stat.saveRealCountByArea(sparkSession, joinTable);
		stat.saveRealCountByService(sparkSession, joinTable);
	}
}
